<!--
 * @Descripttion: (/SensorReportGb)
 * @version: (1.0)
 * @Author: (admin)
 * @Date: (2025-09-11)
 * @LastEditors: (admin)
 * @LastEditTime: (2025-09-11)
-->
<template>
  <div class="app-container">
    <!-- :model属性用于表单验证使用 比如下面的el-form-item 的 prop属性用于对表单值进行验证操作 -->
    <el-form :model="queryParams" size="small" label-position="right" inline ref="queryForm" :label-width="labelWidth" v-show="showSearch" 
      @submit.native.prevent>
      
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- 工具区域 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" v-hasPermi="['sensorreportgb:add']" plain icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" :disabled="single" v-hasPermi="['sensorreportgb:edit']" plain icon="el-icon-edit" size="mini" @click="handleUpdate">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" :disabled="multiple" v-hasPermi="['sensorreportgb:delete']" plain icon="el-icon-delete" size="mini" @click="handleDelete">删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 数据区域 -->
    <el-table :data="dataList" v-loading="loading" ref="table" border highlight-current-row @sort-change="sortChange" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="50" align="center"/>
      <el-table-column prop="id" label="Id" align="center" />
      <el-table-column prop="sysNum" label="SysNum" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="srtdtSysnumber" label="传感器编号" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="srtdtInstallloction" label="测点位置" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="srtdtSensorstyle" label="传感器类型" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="srtdtMonitorvalue" label="测点数值" align="center" />
      <el-table-column prop="srtdtUnit" label="测点单位" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="srtdtState" label="测点状态" align="center">
        <template slot-scope="scope">
          <dict-tag :options="srtdtStateOptions" :value="scope.row.srtdtState" />
        </template>
      </el-table-column>
      <el-table-column prop="srtdtMindata" label="最小值" align="center" />
      <el-table-column prop="srtdtAverdata" label="平均值" align="center" />
      <el-table-column prop="srtdtMaxdata" label="最大值" align="center" />
      <el-table-column prop="srtdtAlarmcont" label="报警次数" align="center" />
      <el-table-column prop="srtdtRefreshtime" label="刷新时间" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="srtdtCelectwav1" label="波长1" align="center" />
      <el-table-column prop="srtdtCelectwav2" label="波长2" align="center" />
      <el-table-column prop="srtdtCelectwav3" label="波长3" align="center" />
      <el-table-column prop="srtdtCelectwav4" label="波长4" align="center" />
      <el-table-column prop="srtdtBasepoint" label="基点" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="siitMininggrouping" label="分组" align="center" />
      <el-table-column prop="siitMiningface" label="工作面" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="siitAlarmstatus" label="SiitAlarmstatus" align="center">
        <template slot-scope="scope">
          <dict-tag :options="siitAlarmstatusOptions" :value="scope.row.siitAlarmstatus" />
        </template>
      </el-table-column>
      <el-table-column prop="subStationNum" label="SubStationNum" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="imgaddress" label="Imgaddress" align="center">
        <template slot-scope="scope">
          <el-image class="table-td-thumb" fit="contain" :src="scope.row.imgaddress" :preview-src-list="[scope.row.imgaddress]">
            <div slot="error"><i class="el-icon-document" /></div>
          </el-image>
        </template>
      </el-table-column>
      <el-table-column prop="x" label="X" align="center" />
      <el-table-column prop="y" label="Y" align="center" />

      <el-table-column label="操作" align="center" width="140">
        <template slot-scope="scope">
          <el-button size="mini" v-hasPermi="['sensorreportgb:edit']" type="success" icon="el-icon-edit" title="编辑" 
            @click="handleUpdate(scope.row)"></el-button>      
          <el-button size="mini" v-hasPermi="['sensorreportgb:delete']" type="danger" icon="el-icon-delete" title="删除" 
            @click="handleDelete(scope.row)"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination class="mt10" background :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 添加或修改对话框 -->
    <el-dialog :title="title" :lock-scroll="false" :visible.sync="open" >
      <el-form ref="form" :model="form" :rules="rules" :label-width="formLabelWidth">
        <el-row :gutter="20">
            
          <el-col :lg="12" v-if="opertype == 2">
            <el-form-item label="Id">{{form.id}}</el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="SysNum" prop="sysNum">
              <el-input v-model="form.sysNum" placeholder="请输入SysNum" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="传感器编号" prop="srtdtSysnumber">
              <el-input v-model="form.srtdtSysnumber" placeholder="请输入传感器编号" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="测点位置" prop="srtdtInstallloction">
              <el-input v-model="form.srtdtInstallloction" placeholder="请输入测点位置" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="传感器类型" prop="srtdtSensorstyle">
              <el-input v-model="form.srtdtSensorstyle" placeholder="请输入传感器类型" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="测点数值" prop="srtdtMonitorvalue">
              <el-input v-model="form.srtdtMonitorvalue" placeholder="请输入测点数值" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="测点单位" prop="srtdtUnit">
              <el-input v-model="form.srtdtUnit" placeholder="请输入测点单位" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="测点状态" prop="srtdtState">
              <el-radio-group v-model="form.srtdtState">
                <el-radio v-for="item in srtdtStateOptions" :key="item.dictValue" :label="item.dictValue">{{item.dictLabel}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="最小值" prop="srtdtMindata">
              <el-input v-model="form.srtdtMindata" placeholder="请输入最小值" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="平均值" prop="srtdtAverdata">
              <el-input v-model="form.srtdtAverdata" placeholder="请输入平均值" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="最大值" prop="srtdtMaxdata">
              <el-input v-model="form.srtdtMaxdata" placeholder="请输入最大值" />
            </el-form-item>
          </el-col>
    
          <el-col :lg="12">
            <el-form-item label="报警次数" prop="srtdtAlarmcont">
              <el-input v-model="form.srtdtAlarmcont" placeholder="请输入报警次数" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="刷新时间" prop="srtdtRefreshtime">
              <el-date-picker v-model="form.srtdtRefreshtime" type="datetime" placeholder="选择日期时间"></el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="波长1" prop="srtdtCelectwav1">
              <el-input v-model="form.srtdtCelectwav1" placeholder="请输入波长1" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="波长2" prop="srtdtCelectwav2">
              <el-input v-model="form.srtdtCelectwav2" placeholder="请输入波长2" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="波长3" prop="srtdtCelectwav3">
              <el-input v-model="form.srtdtCelectwav3" placeholder="请输入波长3" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="波长4" prop="srtdtCelectwav4">
              <el-input v-model="form.srtdtCelectwav4" placeholder="请输入波长4" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="基点" prop="srtdtBasepoint">
              <el-input v-model="form.srtdtBasepoint" placeholder="请输入基点" />
            </el-form-item>
          </el-col>
    
          <el-col :lg="12">
            <el-form-item label="分组" prop="siitMininggrouping">
              <el-input v-model="form.siitMininggrouping" placeholder="请输入分组" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="工作面" prop="siitMiningface">
              <el-input v-model="form.siitMiningface" placeholder="请输入工作面" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="SiitAlarmstatus" prop="siitAlarmstatus">
              <el-radio-group v-model="form.siitAlarmstatus">
                <el-radio v-for="item in siitAlarmstatusOptions" :key="item.dictValue" :label="item.dictValue">{{item.dictLabel}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="SubStationNum" prop="subStationNum">
              <el-input v-model="form.subStationNum" placeholder="请输入SubStationNum" />
            </el-form-item>
          </el-col>

          <el-col :lg="24">
            <el-form-item label="Imgaddress" prop="imgaddress">
              <UploadImage v-model="form.imgaddress" column="imgaddress" @input="handleUploadSuccess" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="X" prop="x">
              <el-input v-model="form.x" placeholder="请输入X" />
            </el-form-item>
          </el-col>


        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="text" @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>

  </div>
</template>
<script>
import { 
  listSensorReportGb,
  addSensorReportGb,
  delSensorReportGb,
  updateSensorReportGb,
  getSensorReportGb,
} from '@/api/gb/sensorReportGb.js';

export default {
  name: "sensorreportgb",
  data() {
    return {
      labelWidth: "100px",
      formLabelWidth:"100px",
      // 选中id数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 遮罩层
      loading: false,
      // 显示搜索条件
      showSearch: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sort: undefined,
        sortType: undefined,
      },
      // 弹出层标题
      title: "",
      // 操作类型 1、add 2、edit
      opertype: 0,
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      columns: [
        { index: 0, key: 'id', label: `Id`, checked:  true  },
        { index: 1, key: 'sysNum', label: `SysNum`, checked:  true  },
        { index: 2, key: 'srtdtSysnumber', label: `传感器编号`, checked:  true  },
        { index: 3, key: 'srtdtInstallloction', label: `测点位置`, checked:  true  },
        { index: 4, key: 'srtdtSensorstyle', label: `传感器类型`, checked:  true  },
        { index: 5, key: 'srtdtMonitorvalue', label: `测点数值`, checked:  true  },
        { index: 6, key: 'srtdtUnit', label: `测点单位`, checked:  true  },
        { index: 7, key: 'srtdtState', label: `测点状态`, checked:  true  },
        { index: 8, key: 'srtdtMindata', label: `最小值`, checked:  true  },
        { index: 9, key: 'srtdtAverdata', label: `平均值`, checked:  false  },
        { index: 10, key: 'srtdtMaxdata', label: `最大值`, checked:  false  },
        { index: 11, key: 'srtdtAlarmcont', label: `报警次数`, checked:  false  },
        { index: 12, key: 'srtdtRefreshtime', label: `刷新时间`, checked:  false  },
        { index: 13, key: 'srtdtCelectwav1', label: `波长1`, checked:  false  },
        { index: 14, key: 'srtdtCelectwav2', label: `波长2`, checked:  false  },
        { index: 15, key: 'srtdtCelectwav3', label: `波长3`, checked:  false  },
        { index: 16, key: 'srtdtCelectwav4', label: `波长4`, checked:  false  },
        { index: 17, key: 'srtdtBasepoint', label: `基点`, checked:  false  },
        { index: 18, key: 'siitMininggrouping', label: `分组`, checked:  false  },
        { index: 19, key: 'siitMiningface', label: `工作面`, checked:  false  },
        { index: 20, key: 'siitAlarmstatus', label: `SiitAlarmstatus`, checked:  false  },
        { index: 21, key: 'subStationNum', label: `SubStationNum`, checked:  false  },
        { index: 22, key: 'imgaddress', label: `Imgaddress`, checked:  false  },
        { index: 23, key: 'x', label: `X`, checked:  false  },
        { index: 24, key: 'y', label: `Y`, checked:  false  },
      ],
      // 测点状态选项列表 格式 eg:{ dictLabel: '标签', dictValue: '0'}
      srtdtStateOptions: [],
      // SiitAlarmstatus选项列表 格式 eg:{ dictLabel: '标签', dictValue: '0'}
      siitAlarmstatusOptions: [],
      // 数据列表
      dataList: [],
      // 总记录数
      total: 0,
      // 提交按钮是否显示
      btnSubmitVisible: true,
      // 表单校验
      rules: {
      },
    };
  },
  created() {    
    // 列表数据查询
    this.getList();

    var dictParams = [
    ];
  },
  methods: {
    // 查询数据
    getList() {
      this.loading = true;
      listSensorReportGb(this.queryParams).then(res => {
         if (res.code == 200) {
           this.dataList = res.data.result;
           this.total = res.data.totalNum;
           this.loading = false;
         }
       })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 重置数据表单
    reset() {
      this.form = {
        id: undefined,
        sysNum: undefined,
        srtdtSysnumber: undefined,
        srtdtInstallloction: undefined,
        srtdtSensorstyle: undefined,
        srtdtMonitorvalue: undefined,
        srtdtUnit: undefined,
        srtdtState: undefined,
        srtdtMindata: undefined,
        srtdtAverdata: undefined,
        srtdtMaxdata: undefined,
        srtdtAlarmcont: undefined,
        srtdtRefreshtime: undefined,
        srtdtCelectwav1: undefined,
        srtdtCelectwav2: undefined,
        srtdtCelectwav3: undefined,
        srtdtCelectwav4: undefined,
        srtdtBasepoint: undefined,
        siitMininggrouping: undefined,
        siitMiningface: undefined,
        siitAlarmstatus: undefined,
        subStationNum: undefined,
        imgaddress: undefined,
        x: undefined,
        y: undefined,
      };
      this.resetForm("form");
    },
    // 重置查询操作
    resetQuery() {
      this.timeRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length != 1
      this.multiple = !selection.length;
    },
     // 自定义排序
    sortChange(column) {
      if (column.prop == null || column.order == null) {
        this.queryParams.sort = undefined;
        this.queryParams.sortType = undefined;
      } else {
        this.queryParams.sort = column.prop;
        this.queryParams.sortType = column.order;
      }

      this.handleQuery();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加";
      this.opertype = 1;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const Ids = row.id || this.ids;

      this.$confirm('是否确认删除参数编号为"' + Ids + '"的数据项？')
        .then(function () {
          return delSensorReportGb(Ids);
        })
        .then(() => {
          this.handleQuery();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getSensorReportGb(id).then((res) => {
        const { code, data } = res;
        if (code == 200) {
          this.open = true;
          this.title = "修改数据";
          this.opertype = 2;

          this.form = {
            ...data,
          };
        }
      });
    },
    //图片上传成功方法
    handleUploadSuccess(column, filelist) {
      this.form[column] = filelist;
    },
    // 测点状态字典翻译
    srtdtStateFormat(row, column) {
      return this.selectDictLabel(this.srtdtStateOptions, row.srtdtState);
    },
    // SiitAlarmstatus字典翻译
    siitAlarmstatusFormat(row, column) {
      return this.selectDictLabel(this.siitAlarmstatusOptions, row.siitAlarmstatus);
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          console.log(JSON.stringify(this.form));
          
          if (this.form.id != undefined && this.opertype === 2) {
            updateSensorReportGb(this.form)
              .then((res) => {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
            })
            .catch((err) => {
                //TODO 错误逻辑
              });
          } else {
            addSensorReportGb(this.form)
              .then((res) => {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
            })
            .catch((err) => {
                //TODO 错误逻辑
              });
          }
        }
      });
    },
  },
};
</script>